<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		
		@media screen and (max-width:450px){
			#content{width:98%;margin:0 auto;border:1px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content{width:450px;margin:0 auto;border:1px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body id='content'>
	<div style='height:100%' id='main' class='l1'>

		<h2 style='text-align:center;margin-top:50px'>创建小区</h2>

		<div style='text-align:center;font-size:12px;margin:20px 0'>当前城市：<span id='current_county'></span></div>


		<div style='width:250px;margin:0 auto'>
			小区名：
			<input type="text" id='area_name' />
		</div>


		<div style='margin:20px auto;text-align:center'>
			<button id='area_submit'>提交</button>
			<span onclick='location.replace("me.html")'><button>返回</button></a>
		</div>

	</div>



</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script>
var tokenSet;
var user_info;

$(function(){
	GetUserInfo(function(user_info){
		GetTokenSet(function(tokenSet){
			tokenSet = tokenSet;

			$('#current_county').text(tokenSet[1]);	//显示当前城市名

			//创建小区
			$('#area_submit').click(function(){
				var area_name = $('#area_name').val().trim();
				var openid = user_info.openid;

				if(!area_name || !openid){
					A('缺少参数！');
					return;
				}

				//获取我的小区列表
				GetMyAreaList(tokenSet[0],function(area_list){
					//C(area_list);
					var tmp_sum = 0;
					for(var i=0;i<area_list.length;i++){
						if(area_list[i].openid == openid){
							tmp_sum ++;
						}
					}
					if(tmp_sum > 4){
						// A('创建个数超限1！');
						// return;
					}
					var area_stat_path = '/area_stat/'+tokenSet[0]+'/'+area_name + '.html';
					ToGetData(area_stat_path,function(stat){	//从upyun缓存判断小区是否存在
						if(stat != 'false'){
							switch(stat){
								case '1':A('小区审核中！');break;
								case '2':A('小区已存在！');break;
								case '3':A('小区已封禁！');break;
							}
						}else{
							var data = {
								type:'create_area',
								area_name:area_name,
							}
							AjaxBefore(data,function(res){
								if(!/^{.*}$/.test(res)){
									A('操作异常！');
									//location.replace('index.html');
									return;
								}
								var tmp = JSON.parse(res);
								sessionStorage.token1 = tmp.token1;
								switch(tmp.stat){
									case 'ok':
										var sess_str = 'localStorage.MyAreaList_'+tokenSet[0] + '=""';
										eval(sess_str);
										A('创建成功，等待审核!');
										location.replace('me.html');
										break;

									case '1':A('小区审核中！');break;
									case '2':A('小区已存在！');break;
									case '3':A('小区已封禁！');break;

									case 'err1':
									case 'err4':
									case 'err5':
									case 'err6':
										A('添加失败！');
										break;
									case 'err7':
										A('创建个数超限2！');
										break;
								}
							},before_interface);
						}
					});
				},5000);
			});
		});
	});



	$('#back').click(function(){
		location.replace('index_me.html');
	});



});
</script>